//加载字典
function dictJudge(value, options, row){
    //sex为自定义字典项
	var statusObj = vm.status;
    for( var i=0;i< statusObj.length;i++ ){
        if(statusObj[i].value == value){
            return '<span>'+statusObj[i].text+'</span>' ;
        }
    }
}

function showMaterial(id){
    vm.look(id);
}

$(function () {
    $("#jqGrid").jqGrid({
        url: baseURL + 'cgs/cgseprbuscheck/list',
        datatype: "json",
        colModel: [			
			{ label: 'id', name: 'id', index: 'id', width: 50, key: true , hidden: true},
			{ label: '用户ID', name: 'applyUserId', index: 'apply_user_id', width: 80 },
			{ label: '公司名称', name: 'companyName', index: 'company_name', width: 80 }, 			
			{ label: '联系人', name: 'linkMan', index: 'link_man', width: 80 }, 			
			{ label: '联系电话', name: 'phone', index: 'phone', width: 80 }, 			
			{ label: '申请事由', name: 'content', index: 'content', width: 80 }, 			
			{ label: '状态', name: 'status', index: 'status', width: 80,formatter:dictJudge },
			{ label: '查看/审核', name: '', index: '', width: 80,
                formatter: function (cellvalue, option, rowObject) {
                    return '&nbsp;&nbsp;<button class="btn btn-info btn-xs" type="button" onclick=showMaterial(\"' + rowObject.id + '\")>查看/审核</button>';
                }
			},
        ],
		viewrecords: true,
        height: 385,
        rowNum: 10,
		rowList : [10,30,50],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
        }
    });
});

var vm = new Vue({
	el:'#rrapp',
	data:{
		showList: true,
		title: null,
		cgsEprBusCheck: {},
        status:[],
        cgsList:[{"id":"2","name":"市车管二分所"},{"id":"3","name":"市车管三分所"}],
        user:{}
	},
    created:function(){
        $.get(baseURL+"/sys/dict/select/eprBuscheckStatus",function (data) {
            vm.status = data.dict.eprBuscheckStatus;
        });
        this.getUser();
    },
	methods: {
		query: function () {
			vm.reload();
		},
		look: function (id) {
			// var id = getSelectedRow();
			if(id == null){
				return ;
			}
			vm.showList = false;
            vm.title = "查看/审核";
            vm.getInfo(id)
		},
		getInfo: function(id){
			$.get(baseURL + "cgs/cgseprbuscheck/info/"+id, function(r){
                vm.cgsEprBusCheck = r.cgsEprBusCheck;
            });
		},
		reload: function (event) {
			vm.showList = true;
			var page = $("#jqGrid").jqGrid('getGridParam','page');
			$("#jqGrid").jqGrid('setGridParam',{ 
                page:page
            }).trigger("reloadGrid");
		},
        getUser: function(){
            $.getJSON(baseURL+"sys/user/info?_"+$.now(), function(r){
                vm.user = r.user;
            });
        },
        cgsCheck:function(){
            let shenhejielun = $("#shenhejielun").val();
            let content = $("#content").val();
            var param = {'status':shenhejielun,'id':vm.cgsEprBusCheck.id};
            if(vm.cgsEprBusCheck.status === '1'){
                param.cgsCheckContent=content;
                param.cgsCheckTime=dateFtt('yyyy-MM-dd hh:mm:ss',new Date());
            }else if(vm.cgsEprBusCheck.status === '2'){
                param.leaderCheckContent=content;
                param.leaderCheckTime=dateFtt('yyyy-MM-dd hh:mm:ss',new Date());
            }

            $.ajax({
                url:baseURL+"cgs/cgseprbuscheck/update",
                type:"POST",
                contentType:"application/json",
                data:JSON.stringify(param),
                success:function(data){
                    if(data.code === 0){
                        alert("操作成功",function(index){
                            vm.reload();
                            $("#myModal").modal('hide');
                        });
                    }else{
                        alert(data.msg);
                    }
                }
            });
        },
        cgsExecute:function(){
            var param = {
                'id':vm.cgsEprBusCheck.id,
                'handleTime':dateFtt('yyyy-MM-dd hh:mm:ss',new Date()),
                'handler':vm.user.username,
                'status':'6'
            };
            $.ajax({
                url:baseURL+"cgs/cgseprbuscheck/update",
                type:"POST",
                contentType:"application/json",
                data:JSON.stringify(param),
                success:function(data){
                    if(data.code === 0){
                        alert("操作成功",function(index){
                            vm.reload();
                            $("#myModal").modal('hide');
                        });
                    }else{
                        alert(data.msg);
                    }
                }
            });
        }
	}
});